Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[01주차 이은지] 백준1105_팔 #5

Merged
merged 1 commit into from
Oct 21, 2023
Merged

Conversation

Eunji1217
Copy link
Member

🔎 문제 소개

🖊️ 풀이

  • 시간 복잡도: (예시) $O(n)$
  • 입력의 크기:
    • $N \leq 2,000,000,000$

처음에 Scanner를 사용하였지만 입력값 제한이 2,000,000,000으로 상당히 크다고 생각하여 BufferedReader을 사용하였고 다음 스트링 문자열을 다시 char의 리스트로 바꾸기 위해 CharAt 을 사용하였다

문제를 풀면서 주의해야할 점은 같은자리 수가 같은 숫자이고 그 숫자가 8인 조건을 계속 만족할때까지만 반복문에 적용시켜 카운트를 세야하는데 처음엔 같은 자리수 같은 숫자일때까지만 반복문을 넣어두고 뒤에 8은 조건문에 붙혀서 틀렸다 조건제시 부분을 헷갈리지 말아야할 것 같다!

System.out.println(0);
} else {
int count = 0;
for( int i = 0; i < L.length()&&L.charAt(i)==R.charAt(i); i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c 스타일의 for문에선 이렇게 높은 수준의 코드를 구현할 일이 없어서 잘 몰랐는데, 당연하지만 for문의 조건 검사절 (중간)에서도 and 연산이 가능하군요!! 잘 생각하지 못했던 부분인데 다음 구현에 참고하겠습니다 🙉

Copy link
Member

@hepheir hepheir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

군더더기 없이 깔끔한 풀이 잘 봤습니다.

이 풀이의 경우에는 입력 N(=R)에 대하여 $O(\log N)$이 되겠네요, 10진수에서의 각 자릿수만 비교하니까요!

Comment on lines +15 to +17
String[] arr = LR.split(" ");
String L = arr[0];
String R = arr[1];
Copy link
Member

@hepheir hepheir Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호, 숫자로 변환하지 않고 바로 문자열로서 처리하셨군요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 카운트만 하면되기도 하고 문자열로 처리하면 배열 처리도 쉬울 것 같아서 문자열로 했슴다!!

System.out.println(0);
} else {
int count = 0;
for( int i = 0; i < L.length()&&L.charAt(i)==R.charAt(i); i++){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charAt에 대해 잘 몰랐는데 덕분에 하나 배워갑니다

@hepheir hepheir merged commit 1d036d3 into dsa-master:main Oct 21, 2023
1 of 2 checks passed
hepheir pushed a commit that referenced this pull request Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants